﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;

namespace PhilosophyQuiz
{
	public class Team
	{
		private	XmlDocument team = new XmlDocument();
		public string Name { get; set; }
		//public string Color { get; set; }
		public string Class { get; set; }
		public string Points { set; get; }

		public string path = String.Format("{0}/{1}", Directory.GetCurrentDirectory(), "teams.xml");

		public void ClearXml()
		{
			team.Load(path);
			team.DocumentElement.RemoveAll();
			team.Save(path);
		}

		public void IncreasePoints(int teamIndex)
		{
			team.Load(path);
			int currPoints = int.Parse(team.DocumentElement.ChildNodes[teamIndex].Attributes[2].InnerText);
			currPoints++;
			team.DocumentElement.ChildNodes[teamIndex].Attributes[2].InnerText = currPoints.ToString();
			team.Save(path);
		}

		public string GetPoints(int teamIndex)
		{
			team.Load(path);
			return team.DocumentElement.ChildNodes[teamIndex].Attributes[2].InnerText;
		}

		public List<Team> List
		{
			get
			{
				List<Team> listTeams = new List<Team>();
				team.Load(path);
				foreach (XmlNode item in team.DocumentElement.ChildNodes)
				{
					listTeams.Add(new Team() { Name = item.Attributes[0].InnerText, Class = item.Attributes[1].InnerText, Points = item.Attributes[2].InnerText });
				}
				return listTeams;
			}
			set
			{}
		}

	}

}
